package com.sunday.framework.restful;

import com.sunday.common.core.converter.MapperConvert;
import com.sunday.common.core.remoting.rest.annotation.OpenApi;
import com.sunday.common.core.remoting.rest.annotation.VoErrorShowType;
import com.sunday.common.core.remoting.rest.page.PageVO;
import com.sunday.common.core.remoting.rest.response.RestResponse;
import com.sunday.framework.controller.RoleController;
import com.sunday.framework.dto.PageRoleReqDTO;
import com.sunday.framework.dto.RemoveRoleReqDTO;
import com.sunday.framework.dto.SaveRoleReqDTO;
import com.sunday.framework.dto.UpdateRoleReqDTO;
import com.sunday.framework.restful.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 角色表 Web 层
 * @author: zsy
 * @Create: 2022/11/07 16:21:06
 */
@Slf4j
@RestController
@RequestMapping("/role")
public class RoleApi {

    @Autowired
    private RoleController roleController;

    /**
     * @Description: 新增 角色表 数据
     * @Param: [saveRoleReqVO]
     * @Return: com.sunday.common.core.remoting.rest.response.RestResponse
     * @author: zsy
     * @Create: 2022/11/07 16:21:06
     */
    @PostMapping("save")
    public RestResponse save(@RequestBody SaveRoleReqVO saveRoleReqVO) {
        SaveRoleReqDTO saveRoleReqDTO = MapperConvert.getFacade().map(saveRoleReqVO, SaveRoleReqDTO.class);
        return RestResponse.resultReturn(roleController.save(saveRoleReqDTO));
    }


    @GetMapping("save")
    public RestResponse getSave() {
        return RestResponse.ok();
    }

    /**
     * @Description: 删除 角色表 数据
     * @Param: [removeRoleReqVO]
     * @Return: com.sunday.common.core.remoting.rest.response.RestResponse
     * @author: zsy
     * @Create: 2022/11/07 16:21:06
     */
    @OpenApi
    @DeleteMapping("remove")
    public RestResponse remove(@RequestBody RemoveRoleReqVO removeRoleReqVO) {
        RemoveRoleReqDTO removeRoleReqDTO = MapperConvert.getFacade().map(removeRoleReqVO, RemoveRoleReqDTO.class);
        return RestResponse.resultReturn(roleController.remove(removeRoleReqDTO));
    }

    /**
     * @Description: 修改 角色表 数据
     * @Param: [updateRoleReqVO]
     * @Return: com.sunday.common.core.remoting.rest.response.RestResponse
     * @author: zsy
     * @Create: 2022/11/07 16:21:06
     */
    @PutMapping("update")
    public RestResponse update(@RequestBody UpdateRoleReqVO updateRoleReqVO) {
        UpdateRoleReqDTO updateRoleReqDTO = MapperConvert.getFacade().map(updateRoleReqVO, UpdateRoleReqDTO.class);
        return RestResponse.resultReturn(roleController.update(updateRoleReqDTO));
    }

    /**
     * @Description: 获取 角色表 分页列表数据
     * @Param: [pageRoleReqVO]
     * @Return: com.sunday.common.core.remoting.rest.response.RestResponse<com.sunday.common.core.remoting.rest.page.PageInfoVO < com.sunday.user.center.rest.vo.role.PageRoleResVO>>
     * @author: zsy
     * @Create: 2022/11/07 16:21:06
     */
    @VoErrorShowType(RestResponse.ShowTypeEnum.NOTIFICATION)
    @PostMapping("page")
    public RestResponse<PageVO<PageRoleResVO>> page(@RequestBody PageRoleReqVO pageRoleReqVO) {
        PageRoleReqDTO pageRoleReqDTO = MapperConvert.getFacade().map(pageRoleReqVO, PageRoleReqDTO.class);
        return RestResponse.convertResultReturn(roleController.page(pageRoleReqDTO), body -> PageVO.of(body, PageRoleResVO.class));
    }

}